package com.syphernova.learning.amst3;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends ActionBarActivity {
	public static final String EXTRA_OPENWITHINTENT = "com.syphernova.learning.asmt3.openwithintent";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button openSocketIntent = (Button)findViewById(R.id.xlinesocket);
        Button openHttpIntent = (Button)findViewById(R.id.xlinehttpclient);
        Button openChromeIntent = (Button)findViewById(R.id.jsonopenchrome);
        Button openCoordIntent = (Button)findViewById(R.id.xlinegmapcoord);
        
        openSocketIntent.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO set the open with intent as socket
		    	Intent intent = new Intent(v.getContext(), InputxJSON.class);
		    	intent.putExtra(EXTRA_OPENWITHINTENT, "OpenSocket");
				startActivity(intent);
			}
		});
        
        openHttpIntent.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO set the open with intent as http client
				Intent intent = new Intent(v.getContext(), InputxJSON.class);
				intent.putExtra(EXTRA_OPENWITHINTENT, "OpenHTTP");
				startActivity(intent);
			}
		});
        
        openCoordIntent.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO get the open with intent as coordinate
				Intent intent = new Intent(v.getContext(), InputxJSON.class);
				intent.putExtra(EXTRA_OPENWITHINTENT, "OpenCoord");
				startActivity(intent);
				
			}
		});
        
        openChromeIntent.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
		        String url = "http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week";
		        Intent intent = new Intent(Intent.ACTION_VIEW);
		        intent.setData(Uri.parse(url));
		        startActivity(intent);
				
			}
		});
        
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    public void openinputxjson(View view){
    	Intent intent = new Intent(this, InputxJSON.class);
    	startActivity(intent);
    }
}
